Skip to main content

Cross Origin Resource Sharing

What is CORS

Ways to workaround in localhost​

  • if you control the backend, enable CORS on the BE server and add CORS header in API call.
    • backend: allow API calls from this domain (localhost) to make an API call
    • frontend: on API request add some headers:
{
'Content-Type': 'application/json',
'X-API-Key': 'secret',
//'Access-Control-Allow-Origin': '*',
}
  • if using third party, add localhost as part of allowed domains or subdomains.

Tech/Tools to use​

  • For simple front-end only: NPX http-server
    • npx http-server --proxy http://localhost:8080\? ./out
    • this creates a http-server that proxies to your local ./out folder and creates an endpoint localhost:8080
  • NGORK - recommended approach
    • Create a publicly accessible domain that is running on your localhost